from django.http import HttpResponse, JsonResponse
from .models import Usertable
from .service import loginService
import json


class loginRoute:

    # 登录
    def login(request):
        req_data = json.loads(request.body.decode())
        result = loginService.sumbit(req_data)
        return JsonResponse(result, safe=False)

    # 创建验证码
    def createVerifyCode(self, request):
        pass

    # 判断是否登录
    def isLogin(self, request):
        pass

    # 注销登录
    def logout(self, request):
        pass

    def testcon(request):
        # print('sdfghjkl;')
        return HttpResponse("12345")

    # 类的私有方法
    def __test(self, request):
        # 没有用到self就不用加
        # 插入数据
        # test = User(id=23,username="user", password="password")
        # test.save()
        # 更新数据
        # test = User.objects.get(id=23)
        # test.password = "apobsbd"
        # test.save()
        # 删除数据
        # test = User.objects.get(id=23)
        # test.delete()
        # 查数据
        # test = User.objects.all()
        # for i in test:
        #     print(i.username,i.password,i.id)
        #     data = {'user':i.username, 'pass':i.password, 'id':i.id}
        # filter相当于SQL中的WHERE，可设置条件过滤结果
        # response2 = Test.objects.filter(id=1) 
        # 获取单个对象
        # response3 = Test.objects.get(id=1) 
        #数据排序
        # Test.objects.order_by("id")
        print("123")
        return HttpResponse("12345678")